package com.five.dao.impl.backstage;

import com.five.dao.backstage.StaffPwdDao;
import com.five.entity.backstage.TStaffPwd;
import com.five.util.DBUtil;

import java.util.List;

public class StaffPwdDaoImpl implements StaffPwdDao {
    //登录
    @Override
    public int find(TStaffPwd sp) {
        String sql = "SELECT * FROM t_staff ts,t_staff_pwd tsp WHERE ts.name=? AND tsp.pwd=? and ts.status=0";
        List list = DBUtil.queryList(sql,sp.getName(),sp.getPwd());
        if(list.size()>0){
            //1为查到
            return 1;
        }else {
            //0为没有查到
            return 0;
        }
    }

    //修改
    @Override
    public int update(String oldPwd,String newPwd, String name) {
        String sql = "update t_staff_pwd set pwd=? where name = ? and pwd=?";
        return DBUtil.manage(sql,newPwd,name,oldPwd);
    }

    //登录时拿取头像
    @Override
    public String path(String name) {
        String sql = "select imgpath from t_staff where name = ?";
        return DBUtil.queryMap(sql,name).get(0).get("imgpath")+"";
    }

    //登录时拿取id
    @Override
    public String ID(String name) {
        String sql = "select id from t_staff where name = ?";
        return DBUtil.queryMap(sql,name).get(0).get("id")+"";
    }

    //登录时拿取roleid
    @Override
    public String roleid(String name) {
        String sql = "select roleid from t_staff where name = ?";
        return DBUtil.queryMap(sql,name).get(0).get("roleid")+"";
    }

}
